$(function() {

	var date = new Date(); //今天
	var date2 = new Date(date.getTime() + 24 * 60 * 60 * 1000); //明天
	var date3 = new Date(date.getTime() + (24 * 60 * 60 * 1000) * 2); //后天
	var date4 = new Date(date.getTime() + (24 * 60 * 60 * 1000) * 3); //大后天
	var month1 = date.getMonth() + 1;
	var month2 = date2.getMonth() + 1;
	var month3 = date3.getMonth() + 1;
	var month4 = date4.getMonth() + 1;
	var day1 = date.getDate();
	var day2 = date2.getDate();
	var day3 = date3.getDate();
	var day4 = date4.getDate();
	var week1 = new Array("周日", "周一", "周二", "周三", "周四", "周五", "周六")[date.getDay()];
	var week2 = new Array("周日", "周一", "周二", "周三", "周四", "周五", "周六")[date2.getDay()];
	var week3 = new Array("周日", "周一", "周二", "周三", "周四", "周五", "周六")[date3.getDay()];
	var week4 = new Array("周日", "周一", "周二", "周三", "周四", "周五", "周六")[date4.getDay()];


	$("#day1").val(month1 + '月' + day1 + '号');
	$("#week1").text(week1);
	$("#day1_text").text(month1 + '月' + day1 + '号');

	$("#day2").val(month2 + '月' + day2 + '号');
	$("#week2").text(week2);
	$("#day2_text").text(month2 + '月' + day2 + '号');

	$("#day3").val(month3 + '月' + day3 + '号');
	$("#week3").text(week3);
	$("#day3_text").text(month3 + '月' + day3 + '号');

	$("#day4").val(month4 + '月' + day4 + '号');
	$("#week4").text(week4);
	$("#day4_text").text(month4 + '月' + day4 + '号');

	//提交送水预约
	$("#sendwater_btn").click(function() {
		var appointDay = $('input[name="appointDay"]:checked').val() || '';
		var appointTime = $("#appointTime").val();
		var telephone = $("#telephone").val();
		var userNo = $("#userNo").val();
		var num = $("#num").val() || 1;

		if (appointDay == '' || appointTime == '' || telephone == '' || userNo == '') {

			$("#textmsg").text('完善信息!');
			$('#modal-alert').modal({
				relatedTarget: this,
			});
			return;
		}

		var data = "title=预约" + category;
		data += "&appointTime=" + appointDay + '  ' + appointTime; //预约时间
		data += "&telephone=" + telephone;
		data += "&userNo=" + userNo;
		data += "&merchantname=" + merchantname;
		data += "&category=" + category;
		data += "&price=" + price;
		data += "&compounds=" + compounds;
		data += "&wxopenId=" + wxopenId; //商家微信openid   发送通知用
		data += "&num=" + num;


		$("#sub_btn").button("loading");
		$.post('/community/addyuyue', data, function(result) {

			$("#sub_btn").button("reset");

			if (result.resultCode == '0') {
				$("#confirm_msg").text('预约成功！现在去查看我的预约吗？');
				$('#modal-confirm').modal({
					relatedTarget: this,
					onConfirm: function(options) {

						location.href = "/webapp/myappoints";

					},
					onCancel: function() {
						location.href = "/community/services?type=" + category;
					}
				});
			} else {

				$("#textmsg").text(result.datas);
				$('#modal-alert').modal({
					relatedTarget: this,
				});
				return;
			}
		});

	});



	//提交预约
	$("#sub_btn").click(function() {

		var appointDay = $('input[name="appointDay"]:checked').val() || '';
		var appointTime = $("#appointTime").val();
		var telephone = $("#telephone").val();

		var address = $("#address").val();
		var expain = $("#expain").val();
		var linkman = $("#linkman").val();

		if (appointDay == '') {

			$("#textmsg").text('请选择预约日期!');
			$('#modal-alert').modal({
				relatedTarget: this,
			});
			return;
		}


		if (appointDay == '' || appointTime == '' || telephone == '' || address == '') {

			$("#textmsg").text('完善预约信息!');
			$('#modal-alert').modal({
				relatedTarget: this,
			});
			return;
		}

		var data = "title=预约" + category;
		data += "&appointTime=" + appointDay + '  ' + appointTime; //预约时间

		data += "&telephone=" + telephone;
		data += "&merchantname=" + merchantname;
		data += "&category=" + category;
		data += "&price=" + price;
		data += "&compounds=" + compounds;
		data += "&address=" + address;
		data += "&expain=" + expain;
		data += "&linkman=" + linkman;
		data += "&wxopenId=" + wxopenId; //商家微信openid   发送通知用

		$("#sub_btn").button("loading");
		$.post('/wx/life/reserve/add', data, function(result) {

			$("#sub_btn").button("reset");
			$("#textmsg").text(result.datas);
			$('#modal-alert').modal({
				relatedTarget: this,
			});
			return;

			if (result.resultCode == '0') {
				//$("#confirm_msg").text('预约成功！现在去查看我的预约吗？');
				// $('#modal-confirm').modal({
				// 	relatedTarget: this,
				// 	onConfirm: function(options) {
				// 		location.href = "/webapp/myappoints";
				// 	},
				// 	onCancel: function() {
				// 		location.href = "/community/services?type=" + category;
				// 	}
				// });

			} 
		});
	});
});